<!-- application/views/scripts/blog/edit.phtml -->
<!-- htmlbox plugin -->
<script language="Javascript" src="/htmlbox.colors.js" type="text/javascript"></script>
<script language="Javascript" src="/htmlbox.styles.js" type="text/javascript"></script>
<script language="Javascript" src="/htmlbox.syntax.js" type="text/javascript"></script>
<script language="Javascript" src="/xhtml.js" type="text/javascript"></script>
<script language="Javascript" src="/htmlbox.full.js" type="text/javascript"></script>

<script type="text/javascript">

$().ready(function() {
	$("#add_blog").hide();
		
	//Use html plungin on some specific textareas by class
	g_blogHtmlBox = $("#ha").css("height","80%").css("width","100%").htmlbox({
	toolbars:[
				[
					// Cut, Copy, Paste
					"separator","cut","copy","paste",
					// Undo, Redo
					"separator","undo","redo",
					// Bold, Italic, Underline, Strikethrough, Sup, Sub
					"separator","bold","italic","underline","strike","sup","sub",
					// Left, Right, Center, Justify
					"separator","justify","left","center","right",
					// Ordered List, Unordered List, Indent, Outdent
					"separator","ol","ul","indent","outdent",
					// Hyperlink, Remove Hyperlink, Image
					"separator","link","unlink","image"
	
				],
				[// Show code
					"separator","code",
					// Formats, Font size, Font family, Font color, Font, Background
					"separator","formats","fontsize","fontfamily",
					"separator","fontcolor","highlight",
				],
				[
				//Strip tags
				"separator","removeformat","striptags","hr","paragraph",
				// Styles, Source code syntax buttons
				"separator","quote","styles","syntax"
				]
			],
			icons:"silk",
			skin:"blue",
			idir:"/images"
	});

	<?php 
		$catAutoComplete="";
		for($i=0; $i<count($this->categories);$i++) {
    		if ($i==0) {
    			$catAutoComplete = "'".$this->categories[$i]['category']."'";
    		} else {
    			$catAutoComplete = $catAutoComplete.",'".$this->categories[$i]['category']."'";
    		}
    	}    		
	?>
	var autocom = $("#autocomplete").autocomplete({
		source: [<?php echo $catAutoComplete;?>],
		minLength:0
	});
	$("#autocomplete").click(function(){autocom.autocomplete( "search" ,"")});
	
	var ac_privilete = $("#ac_privilege").autocomplete({
		source: ['<?php echo Application_Model_Constants::PRIVILEGE_TYPE_PUBLIC_STR;?>','<?php echo Application_Model_Constants::PRIVILEGE_TYPE_PRIVATE_STR;?>'],
		minLength:0
	});
	$("#ac_privilege").click(function(){ac_privilete.autocomplete( "search" ,"")});

});

function showAddBlog(show) {
	setValueForBlogForm("","","","","");
	if(show) {
		$("#add_blog").show();
	} else {
		$("#add_blog").hide();		
	}
}

function setValueForBlogForm(blogId, title, content, tag, category, privilege) {
    $("div#add_blog [name|=bid]").val(blogId);
	$("div#add_blog [name|=title]").val(title);
	g_blogHtmlBox.set_text(content);
	$("div#add_blog [name|=tag]").val(tag);
	$("div#add_blog [name|=category]").val(category);
	$("div#add_blog [name|=privilege]").val(privilege);
}
</script>

<div id="add_blog">
	<form enctype="application/x-www-form-urlencoded" method="post" action="/blog/save" >
		<input type="hidden" name="bid" value=""/>
		title: <input type="text" name="title" size=20/>
		<br><br><p/>
		<textarea id="ha" name="content"></textarea>
		<br><p/>
		Category: <input id="autocomplete" name="category"/>  tags: <input name="tag" type="text" size=20/> Note: Seperate keywords by comma.
		<br>权限：<input id="ac_privilege" name="privilege" value="<?php echo Application_Model_Constants::PRIVILEGE_TYPE_PUBLIC_STR;?>"/>
		<p/>
		<br>
		<!-- a bug that the htmlbox does not set the text to the textarea, do it manually -->
		<input type="submit" value="save" onclick="$('#ha').text(g_blogHtmlBox.get_html());"/>
		<input type="button" value="cancel" onclick="showAddBlog(0);"/>
	</form>
</div>

